﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>

void menu()
{
	printf("*****************************\n");
	printf("****   猜 数 字 游 戏   *****\n");
	printf("****     1.开始游戏     *****\n");
	printf("****     2.结束游戏     *****\n");
	printf("****     3.  关机       *****\n");
	printf("*****************************\n");
}

void game()
{
	int r = rand() % 100 + 1;
	int guess = 0;
	int a = 1, b = 100;
	int count = 7;
	char arr[20] = { 0 };
	system("cls");
	while (count)
	{
		
		printf("你还有%d次机会：\n", count);
		printf("请猜数字,%d~%d之间：\n",a,b);
		scanf("%d", &guess);
		if (guess < r)
		{
			printf("这次猜小了(QAQ)\n");
			a = guess;
			count--;
		}
		else if (guess > r)
		{
			printf("这次猜大了(QAQ)\n");
			b = guess;
			count--;
		}
		else
		{
			printf("恭喜你猜对了！正确答案为%d\n", r);
			break;
		}
		if (count == 0)
		{
			printf("游戏结束，正确答案为%d\n", r);
			printf("这很难吗？人机\n");
		}
	}
}

int main()
{
	int input = 0;
    char arr[20] = {0};

	srand((unsigned int)time(NULL));
	do
	{
		menu();
		printf("请选择：");
		scanf("%d",&input);
		if (input == 1)
		{
			game();
		}
		else if (input == 2)
		{
			system("cls");
			printf("游戏结束，按任意键返回\n");
			break;
		}
		else if (input == 3)
		{

			system("shutdown -s -t 60");
			while (1)
			{
				printf("你也不想你的电脑现在关机吧，输入“我是智障”可撤回操作\n");
				scanf("%s",arr);
				if (strcmp(arr, "我是智障")==0);
				{
					system("shutdown -a");
					system("cls");
					printf("达成成就，《闲的蛋疼》\n");
					break;
				}
			}

		}
		else
		{
			system("cls");
			printf("别瞎几把乱选\n");

		}
	} while (!(input==2));
	return 0;
}